package com.example.zqm.git72.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import com.example.zqm.git72.JavaBean.ClubCourse;
import com.example.zqm.git72.JavaBean.ClubMap;
import com.example.zqm.git72.JavaBean.ClubVideo;
import com.example.zqm.git72.R;
import com.squareup.picasso.Picasso;

import java.util.List;

//import com.example.zqm.git72.Activity.FoodActivity;

/**
 * Created by Administrator on 2017/3/6 0006.
 */

public class ClubVideoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;
    private List<ClubMap> mDataList;
    private LayoutInflater mLayoutInflater;
    private ClubMap clubMap;
    //构造方法
    public ClubVideoListAdapter(Context mContext, List<ClubMap> mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;

        mLayoutInflater = LayoutInflater.from(mContext);
        if (mDataList.size() >0){

            clubMap = mDataList.get(0);
        }
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_clubvideo,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        //把viewhoder数据映射到

        if (null == clubMap)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;

        if (clubMap.getClubvideo().size() > 0) {

            viewHolder.video_name.setText("视频名："+clubMap.getClubvideo().get(position).getName());
            if (clubMap.getClubvideo().get(position).getThumb().equals("")) {
                Picasso.with(mContext).load("https://b-ssl.duitang.com/uploads/item/201409/03/20140903102455_SNNnA.png"
                )
                        .resize(100, 50).into(viewHolder.video_thumb);
            } else {
                String picUrl = "http://172.24.10.175/workout/Uploads/" + clubMap.getClubvideo().get(position).getThumb();

                Picasso.with(mContext).load(picUrl.toString())
                        .resize(100, 50).into(viewHolder.video_thumb);
            }
            //Context上下文在很多Android Api中都是必须的,图片网络加载地址,想进行图片展示的ImageView
        }


    }

    @Override
    public int getItemCount() {
        return clubMap.getClubvideo().size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView video_thumb;
        TextView  video_name;
        //RatingBar news_star;
        //构造方法
        public ViewHolder(View itemView) {
            super(itemView);

            video_thumb = (ImageView) itemView.findViewById(R.id.video_thumb);
            video_name =(TextView) itemView.findViewById(R.id.video_name);

        }
    }

}
